//
//  WebInfo_GetView_Task.m
//  iphone.mobileoa
//  获取信息阅读列表
//  Created by 李亚春 on 13-5-28.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "WebInfo_GetView_Task.h"
#import "WebServiceHelper.h"
#import "StringUtil.h"
#import "GDataXMLNode.h"
#import "InfoListModel.h"

@implementation WebInfo_GetView_Task

-(void)execute
{
    NSString *ValidateData = [self.params objectForKey:@"ValidateData"];
    NSString *url = [self.params objectForKey:@"url"];
    NSString *wsNamespace = [self.params objectForKey:@"namespace"];
    NSString *userguid = [self.params objectForKey:@"userguid"];
    NSString *pagesize = [self.params objectForKey:@"pagesize"];
    NSString *keyword = [self.params objectForKey:@"keyword"];
    NSString *categoryguid = [self.params objectForKey:@"categoryguid"];
    NSString *CurrentPageIndex = [self.params objectForKey:@"CurrentPageIndex"];
    WebServiceHelper *webserviceHelper = [[WebServiceHelper alloc]initWebServiceWithUrl:url wsNamespace:wsNamespace method:@"WebInfo_GetView"];
    NSString *ParasXml = @"<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><KeyWord>%@</KeyWord><CurrentPageIndex>%@</CurrentPageIndex><PageSize>%@</PageSize><CategoryGuid>%@</CategoryGuid></paras>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,keyword,CurrentPageIndex,pagesize,categoryguid];
    ParasXml = [StringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    
    NSLog(@"%@",bs);
    
    [self sendDataRefreshUI:bs];
}

+(NSMutableArray *)getInfoListModelArray:(NSString *)_xmldata
{
    _xmldata = [StringUtil getXMLFormatedAttributeIncludeTag:_xmldata :@"InfoList"];
    
    GDataXMLDocument *doc = [[[GDataXMLDocument alloc] initWithXMLString:_xmldata  options:0 error:nil]autorelease];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"Info"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        InfoListModel *m = [[InfoListModel alloc]init];
        GDataXMLElement *InfoGuid = [[arr elementsForName:@"InfoGuid"] objectAtIndex:0];
        m.InfoGuid = [InfoGuid stringValue];
        
        GDataXMLElement *txtTitle = [[arr elementsForName:@"txtTitle"] objectAtIndex:0];
        m.txtTitle = [txtTitle stringValue];
        
        GDataXMLElement *Content = [[arr elementsForName:@"Content"] objectAtIndex:0];
        m.Content = [Content stringValue];
        
        GDataXMLElement *PostUserName = [[arr elementsForName:@"PostUserName"] objectAtIndex:0];
        m.PostUserName = [PostUserName stringValue];
        
        GDataXMLElement *PostDate = [[arr elementsForName:@"PostDate"] objectAtIndex:0];
        m.PostDate = [PostDate stringValue];
        
        GDataXMLElement *InfoProperty = [[arr elementsForName:@"InfoProperty"] objectAtIndex:0];
        m.InfoProperty = [InfoProperty stringValue];
        
        GDataXMLElement *IsRead = [[arr elementsForName:@"IsRead"] objectAtIndex:0];
        m.IsRead = [IsRead stringValue];
        
        [listmp addObject:m];
        [m release];
    }
    
    return [listmp autorelease];
}

@end
